package com.hmall.order.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/*
 *   Description MqConfig
 *   @author zhangyan
 *   @time   2024/11/21
 */
@Configuration
public class MqConfig {
    @Bean
    public DirectExchange orderExchange() {
        return new DirectExchange("order.exchange");
    }

    @Bean
    public Queue orderQueue() {
        return QueueBuilder
                .durable("order.queue")
                //消息超时未支付，进入死信队列
                .ttl(60000*30)
                .deadLetterExchange("order.dead.exchange")
                .deadLetterRoutingKey("order.dead.routing")
                .build();
    }
    @Bean
    public Binding orderBinding() {
        return BindingBuilder.bind(orderQueue()).to(orderExchange()).with("order.routing");
    }
}
